﻿<UserControl x:Class="Quizio.Views.Home"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600"
             DataContext="{Binding HomeViewModel}">

    <Grid x:Name="root" Style="{StaticResource ContentRoot}">
        <ScrollViewer>
            <StackPanel MinWidth="200">
                <TextBlock>
                    <Run Text="Hallo, "></Run>
                    <Run Text="{Binding Aggregator.User.Name}" FontWeight="Bold"></Run>
                </TextBlock>
                <Grid Width="650" Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="300"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left">
                        <Label Content="Neuigkeiten:" Margin="0,10" FontWeight="Bold" />
                        <ScrollViewer MaxHeight="300">
                            <ItemsControl ItemsSource="{Binding Aggregator.Notifications}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock TextWrapping="Wrap" Text="{Binding Message}"  Margin="0,5"/>
                                        </Grid>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                    </StackPanel>
                    <StackPanel Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Width="Auto">
                        <Label Content="Herausforderungen:" Margin="0,10" FontWeight="Bold" />
                        <TextBlock Text="Keine Herausforderungen vorhanden." Visibility="{Binding ShowChallengeListEmpty}"></TextBlock>
                        <ScrollViewer MaxHeight="350">
                            <ItemsControl x:Name="challanges" ItemsSource="{Binding Aggregator.OpenChallenges}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderBrush="{DynamicResource Accent}" BorderThickness="1" CornerRadius="1" 
                                        Height="Auto" Width="Auto" Margin="0,0,0,10" Padding="7">
                                            <StackPanel Width="Auto">
                                                <StackPanel Orientation="Horizontal" Width="Auto">
                                                    <TextBlock TextWrapping="Wrap" Margin="0,0,10,0" FontWeight="Bold" Text="{Binding ChallengeGame.Category.Name}"/>
                                                    <TextBlock Text="|  "></TextBlock>
                                                    <TextBlock TextWrapping="Wrap" FontWeight="Bold" Text="{Binding ChallengeGame.PlayedQuiz.Title}"/>
                                                </StackPanel>
                                                <TextBlock Margin="0,10,0,0">Von:
                                        <Run FontWeight="Bold" Text="{Binding ChallengeGame.Player.Name}"/>
                                                </TextBlock>
                                                <TextBlock TextWrapping="Wrap" Text="{Binding ChallengeText}"/>
                                                <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                                                    <mui:ModernButton Content="annehmen" Margin="0,0,10,0" 
                                                                      Command="{Binding ElementName=challanges, Path=DataContext.RespondChallenge}" 
                                                                      CommandParameter="{Binding}"/>
                                                    <mui:ModernButton Content="ablehnen"
                                                                      Command="{Binding ElementName=challanges, Path=DataContext.DeclineChallange}" 
                                                                      CommandParameter="{Binding}"/>
                                                </StackPanel>
                                            </StackPanel>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </ScrollViewer>
        <mui:ModernProgressRing Width="50" Height="50" IsEnabled="True" IsActive="{Binding ShowOrHide}" VerticalAlignment="Bottom" HorizontalAlignment="Center">
        </mui:ModernProgressRing>
        <TextBlock Visibility="{Binding ShowCountDown}" VerticalAlignment="Bottom" HorizontalAlignment="Center">
            <Run Text="Spiel beginnt in "></Run>
            <Run Text="{Binding TimerTickCountDown}"></Run>
            <Run Text="... mach dich bereit!"></Run>
        </TextBlock>
    </Grid>
</UserControl>